<?php
namespace app\index\controller;
use think\Db;
class Index extends Base{
    public function index(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
        if($customer['platformpc_state']==1){
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
            $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            
        }else{
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',0)->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',0)->find();
            $banner=Db::name('banner')->where('cus_id',0)->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',0)->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',0)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',0)->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            $this->assign('cus_id',0);
        }
        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('banner',$banner);
        $this->assign('comads',$comads);
        $this->assign('products',$products);
        $this->assign('case',$case);
        $this->assign('news',$news);
        $this->assign('partner',$partner);
        if($customer['templatepc']==1){
            return $this->fetch();
        }elseif($customer['templatepc']==2){
            $this->redirect('index/template2', ['cus_id' => input("param.cus_id")]);
        }elseif($customer['templatepc']==3){
            $this->redirect('index/template3', ['cus_id' => input("param.cus_id")]);
        }elseif($customer['templatepc']==4){
            $this->redirect('index/template4', ['cus_id' => input("param.cus_id")]);
        }elseif($customer['templatepc']==5){
            $this->redirect('index/template5', ['cus_id' => input("param.cus_id")]);
        }elseif($customer['templatepc']==6){
            $this->redirect('index/template6', ['cus_id' => input("param.cus_id")]);
        }
    }
    public function template2(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
        if($customer['platformpc_state']==1){
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
            $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            
        }else{
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',0)->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',0)->find();
            $banner=Db::name('banner')->where('cus_id',0)->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',0)->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',0)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',0)->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            $this->assign('cus_id',0);
        }
        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('banner',$banner);
        $this->assign('comads',$comads);
        $this->assign('products',$products);
        $this->assign('case',$case);
        $this->assign('news',$news);
        $this->assign('partner',$partner);
        return $this->fetch();
    }
    public function template3(){
        Db::name('actives')->insert(['cus_id'=>input("param.cus_id"),'time'=>time()]);
        $customer=Db::name('customer')->where('id',input("param.cus_id"))->find();
        if($customer['platformpc_state']==1){
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',input("param.cus_id"))->find();
            $banner=Db::name('banner')->where('cus_id',input("param.cus_id"))->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',input("param.cus_id"))->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
            $procates=Db::name('cate')->where('type',1)->where('cus_id',input("param.cus_id"))->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            
        }else{
            $navs=Db::name('nav')->where('nav_type',3)->where('cus_id',0)->where('state',1)->order('sort asc')->select();
            $logo=Db::name('aboutus')->where('cus_id',0)->find();
            $banner=Db::name('banner')->where('cus_id',0)->where('state',1)->where('mtype',0)->order('sort desc')->select();
            $comads=Db::name('news')->where('cus_id',0)->where('state',1)->order('sort desc')->limit(3)->select();
            $products=Db::name('product')->where('cus_id',0)->where('state',1)->where('flag',1)->order('id desc')->limit(3)->select();
            $case=Db::name('case')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->find();
            $news=Db::name('news')->where('cus_id',0)->where('state',1)->where('flag',1)->order('sort desc')->limit(3)->select();
            $partner=Db::name('partner')->where('cus_id',0)->where('state',1)->order('sort desc')->select();
            $procates=Db::name('cate')->where('type',1)->where('cus_id',0)->where('state',1)->order('sort desc')->select();
            $this->assign('cus_id',input("param.cus_id"));
            $this->assign('cus_id',0);
        }

        if (input('get.cate_id')) {
            $allpro=Db::name('product')->where('cus_id',input("param.cus_id"))->where('cate_id',input("param.cate_id"))->where('state',1)->order('id desc')->paginate(6);
            $allpros=Db::name('product')->where('cus_id',input("param.cus_id"))->where('cate_id',input("param.cate_id"))->where('state',1)->order('id desc')->select();
            $this->assign('cate_id',input('get.cate_id'));
        }else{
            $allpro=Db::name('product')->where('cus_id',input("param.cus_id"))->where('state',1)->order('id desc')->paginate(6);
            $allpros=Db::name('product')->where('cus_id',input("param.cus_id"))->where('state',1)->order('id desc')->select();
            // $this->assign('cate_id',0);
            $this->assign('cate_id',$procates[0]['id']);
        }
        $data=$allpro->all();
        $this->assign('customer',$customer);
        $this->assign('data',$data);
        $this->assign('allpro',$allpro);
        $this->assign('allpros',$allpros);

        $this->assign('customer',$customer);
        $this->assign('navs',$navs);
        $this->assign('url','/index.php/index/');
        $this->assign('logo',$logo);
        $this->assign('banner',$banner);
        $this->assign('comads',$comads);
        $this->assign('products',$products);
        $this->assign('case',$case);
        $this->assign('news',$news);
        $this->assign('partner',$partner);
        $this->assign('procates',$procates);
        return $this->fetch();
    }
}
